﻿using AutoMapper;
using SGSBillBoard.Context;
using SGSBillBoard.DTO.Model;
using SGSBillBoard.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace SGSBillBoard.Test
{

    class Program
    {
        static void Main(string[] args)
        {

            //Database.SetInitializer<SGSContext>(new SGSInitializer());
            //SGSContext context = new SGSContext();
            //context.Database.Initialize(true);
            IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
            string hostName = ipGlobalProperties.HostName;
            string domainName = ipGlobalProperties.DomainName;


            PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, domainName);
            UserPrincipal userPrincipal = new UserPrincipal(principalContext);
            PrincipalSearcher principalSearcher = new PrincipalSearcher(userPrincipal);

            StringBuilder sb = new StringBuilder(); 
            foreach (UserPrincipal userPrincipalSearchResult in principalSearcher.FindAll())
            {
                sb.AppendLine(string.Format("UPN:{0}", userPrincipalSearchResult.UserPrincipalName));
                //sb.AppendLine(string.Format("姓氏Last Name:{0}", userPrincipalSearchResult.Surname));
        
                //sb.AppendLine(string.Format("First Name名:{0}", userPrincipalSearchResult.GivenName));
                sb.AppendLine(string.Format("名称:{0}", userPrincipalSearchResult.Name));
                sb.AppendLine(string.Format("Email:{0}", userPrincipalSearchResult.EmailAddress));
      
                //sb.AppendLine(string.Format("上次登录时间:{0}", userPrincipalSearchResult.LastLogon));
            }
            //userPrincipal.Dispose();
            //Console.WriteLine(sb.ToString());

            Console.WriteLine("OK");
            Console.ReadKey();

        }



    }


}
